package kp.rpc.fault.retry.factory;

import kp.rpc.fault.retry.RetryStrategy;
import kp.rpc.fault.retry.impl.NoRetryStrategy;
import kp.rpc.model.RpcResponse;
import kp.rpc.spi.SpiLoader;

import java.util.concurrent.Callable;

/**
 * @author tzf
 * @description: 重试策略工厂
 * @date: 2024/6/7 14:17
 */

public class RetryStrategyFactory {
    static {
        SpiLoader.load(RetryStrategy.class);
    }

    //默认重试器
    private final static RetryStrategy DEFAULT_RETRY_STRATEGY = new NoRetryStrategy();

    public static RetryStrategy getInstance(String key) {
        Object instance = SpiLoader.getInstance(RetryStrategy.class, key);
        return instance == null ? DEFAULT_RETRY_STRATEGY : (RetryStrategy) instance;
    }
}
